<template>
	<view class="wrap safe-area">
		<view class="wrap-list">
			<block v-for="(item, index) in list" :key="index">
				<view class="item flex align-center">
					<view class="left">
						<view class="title">
							{{ item.memo }}
						</view>
						
						<view class="time">
							{{ item.createtime_text }}
						</view>
					</view>
					
					<view class="right">
						<text>{{ item.money }}</text>
						<text class="unit">元</text>
					</view>
				</view>
			</block>
		</view>
		
		<wanl-empty v-if="list.length === 0" text="暂无数据" />
	</view>
</template>

<script>
	import { moneyLog } from "@/utils/API.js";
	export default {
		data() {
			return {
				page: 1,
				total: 0,
				list: []
			};
		},
		onLoad() {
			this.onRefresh();
		},
		onPullDownRefresh() {
			this.onRefresh();
		},
		onReachBottom() {
			if (this.list.length < this.total) {
				this.page++;
				this.getData();
			}
		},
		methods: {
			/**
			 * 刷新
			 */
			onRefresh() {
				this.page = 1;
				this.list = [];
				this.getData()
			},
			/**
			 * 网络请求
			 */
			getData() {
				moneyLog(this.page).then(res => {
					const list = res.data.data;
					this.total = res.data.total;
					
					if (this.page == 1) {
						this.list = list;
					} else {
						this.list = this.list.concat(list);
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	.wrap {
		padding: 30rpx;
		box-sizing: border-box;
		
		.wrap-list {
			width: 100%;
			overflow: hidden;
			
			.item {
				width: 100%;
				margin-bottom: 30rpx;
				background-color: white;
				border-radius: 20rpx;
				padding: 40rpx 30rpx;
				box-sizing: border-box;
				gap: 20rpx;
				
				&:last-child {
					margin-bottom: 0rpx;
				}
				
				.left {
					flex: 1;
					overflow: hidden;
					
					.title {
						color: #333333;
						font-size: 30rpx;
					}
					
					.time {
						margin-top: 10rpx;
						color: #999999;
						font-size: 26rpx;
					}
				}
				
				.right {
					color: #333333;
					font-size: 40rpx;
					font-weight: bold;
					
					.unit {
						font-weight: normal !important;
						font-size: 26rpx !important;
					}
				}
			}
		}
	}
</style>
